<!DOCTYPE html>

<html>
<head>
	<title>AIL-SYNC</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png')}}">
	<!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">

	<!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
  <script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
  <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>

	<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>

</head>

<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'settings/menu_sidebar.html' %}

			<div class="col-12 col-lg-10" id="core_content">

				<div class="d-flex justify-content-center my-4">
					<div class="input-group mb-2 mr-sm-2" style="max-width: 30rem;">
						<div class="input-group-prepend">
							<div class="input-group-text bg-dark text-white">
								<b>AIL UUID</b>
							</div>
						</div>
						<div class="form-control">
							{{ ail_uuid }}
							<input id="ail_uuid" name="ail_uuid" type="text" value="{{ ail_uuid }}" hidden>
						</div>
						<div class="input-group-append">
							<button type="button" class="btn btn-secondary" onclick="copy_ail_uuid()">
								<i class="fas fa-clipboard"></i>
							</button>
						</div>
					</div>

				</div>


				<h1>Connected - AIL Sync:</h3>

				<table id="table_servers" class="table table-striped border-primary">
          <thead class="bg-dark text-white">
            <tr>
                <th>uuid</th>
                <th>url</th>
                <th>description</th>
                <th>sync queues</th>
								<th>sync mode</th>
								<th></th>
            </tr>
          </thead>
          <tbody style="font-size: 15px;">
            {% for dict_server in l_servers %}
              <tr class="border-color: blue;">
                <td>
									<a href="{{ url_for('ail_2_ail_sync.ail_server_view') }}?uuid={{ dict_server['uuid'] }}">
										{{ dict_server['uuid']}}
									</a>
								</td>
                <td>{{ dict_server['url']}}</td>
                <td>{{ dict_server['description']}}</td>
                <td class="text-center">
									{% for queue_uuid in dict_server['sync_queues'] %}
                  	<a href="{{ url_for('ail_2_ail_sync.sync_queue_view') }}?uuid={{queue_uuid}}">
                      {{queue_uuid}}</br>
                    </a>
                  {% endfor %}
                </td>
								<td>
									{% if dict_server['server_sync_mode']['api'] %}
                  	API
                  {% endif %}
									{% if dict_server['server_sync_mode']['pull'] %}
                  	PULL
                  {% endif %}
									{% if dict_server['server_sync_mode']['push'] %}
                  	PUSH
                  {% endif %}
								</td>
								<td>
									{% if dict_server['server_sync_mode']['push'] %}
										<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_client_kill') }}?uuid={{ dict_server['uuid'] }}">
											<button type="button" class="btn btn-danger px-1 py-0">
												<i class="fas fa-times"></i> kill
											</button>
											<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_client_relaunch') }}?uuid={{ dict_server['uuid'] }}">
												<button type="button" class="btn btn-info px-1 py-0">
													<i class="fas fa-redo-alt"></i> reLaunch
												</button>
											</a>
										</a>
                  {% endif %}
								</td>
              </tr>
            {% endfor %}
          </tbody>
        </table>


				<h1>Connected - Remote Sync:</h3>

				<table id="table_servers" class="table table-striped border-primary">
          <thead class="bg-dark text-white">
            <tr>
                <th>uuid</th>
                <th>url</th>
                <th>description</th>
                <th>sync mode</th>
								<th></th>
            </tr>
          </thead>
          <tbody style="font-size: 15px;">
            {% for dict_server in l_clients %}
              <tr class="border-color: blue;">
                <td>
									<a href="{{ url_for('ail_2_ail_sync.ail_server_view') }}?uuid={{ dict_server['uuid'] }}">
										{{ dict_server['uuid']}}
									</a>
								</td>
                <td>{{ dict_server['url']}}</td>
                <td>{{ dict_server['description']}}</td>
                <td class="text-center">
									{% if dict_server['client_sync_mode']['api'] %}
                  	API
                  {% endif %}
									{% if dict_server['client_sync_mode']['pull'] %}
                  	PULL
                  {% endif %}
									{% if dict_server['client_sync_mode']['push'] %}
                  	PUSH
                  {% endif %}
                </td>
								 <td>
									 <a href="{{ url_for('ail_2_ail_sync.ail_server_client_kill') }}?uuid={{ dict_server['uuid'] }}">
										 <button type="button" class="btn btn-danger px-1 py-0">
											 <i class="fas fa-times"></i> kill
										 </button>
									 </a>
								 </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>

			</div>

		</div>
	</div>

</body>

<script>
$(document).ready(function(){
	$('#nav_sync').removeClass("text-muted");
	$("#nav_ail_sync").addClass("active");

  $('#table_servers').DataTable({
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
        "iDisplayLength": 10,
        "order": [[ 1, "desc" ]]
  });

});

function copy_ail_uuid() {
	ail_uuid = $('#ail_uuid').val();
	navigator.clipboard.writeText(ail_uuid);
}

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}

</script>
